#!/bin/bash

Current_TIME=`date "+%Y-%m-%d %H:"`
File_TIME=`date "+%Y%m%d"`

#正佳
z1=`zabbix_get -s 10.64.2.1 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/121.8.183.252/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`
z2=`zabbix_get -s 10.64.2.2 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/121.8.183.252/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`
z3=`zabbix_get -s 10.64.2.1 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/210.21.31.88/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`
z4=`zabbix_get -s 10.64.2.2 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/210.21.31.88/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`


#环讯scg1
h1=`zabbix_get -s 10.64.2.1 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/121.10.1.178/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`
h2=`zabbix_get -s 10.64.2.2 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/121.10.1.178/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`

#环讯scg2
h3=`zabbix_get -s 10.64.2.1 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/121.10.1.179/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`
h4=`zabbix_get -s 10.64.2.2 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/121.10.1.179/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`

#珠江zm
zj1=`zabbix_get -s 10.64.2.1 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/125.94.0.254/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`
zj2=`zabbix_get -s 10.64.2.2 -p 10050 -k radius_check_ac["-c %z",/home/radius/radius_iGuangdong/var/log/radius/radacct/125.94.0.254/auth-detail-${File_TIME}] | grep "${Current_TIME}" | wc -l`

if (( ${z1}==1 || ${z2}==1 || ${z3}==1 || ${z4}==1)); then
	zhengjia=1
else
	zhengjia=0
fi

if (( ${h1}==1 || ${h2}==1 )) ; then
	huanxun=1
else
	huanxun=0
fi

if (( ${h3}==1 || ${h4}==1 )) ; then
	huanxun2=1
else
	huanxun2=0
fi


if (( ${zj1}==1 || ${zj2}==1 )) ; then
	zhujiang=1
else
	zhujiang=0
fi

if (( ${zhengjia}==1 && ${huanxun}==1 && ${huanxun2}==1 && ${zhujiang}==1 )) ; then
	echo "`date "+%Y-%m-%d %H:%M:%S"` 没问题" >> /home/rduser/check_ac_available/ac.log
	exit
fi


#mail
send_mail(){
local -a Mail_error

if (( ${zhengjia}==0 )); then
	zhengjia_error="过去2小时,正佳场点认证有问题!"
	Mail_error+=(${zhengjia_error})
fi

if (( ${huanxun}==0 )); then
	huanxun_error="过去2小时,环讯场点scg1认证有问题!"
	Mail_error+=(${huanxun_error})
fi

if (( ${huanxun2}==0 )); then
	huanxun_error="过去2小时,环讯场点scg2认证有问题!"
	Mail_error+=(${huanxun2_error})
fi


if (( ${zhujiang}==0 )); then
	huanxun_error="过去2小时,珠江场点认证有问题!"
	Mail_error+=(${zhujiang_error})
fi

echo "`date "+%Y-%m-%d %H:%M:%S"`" ${Mail_error[*]} >> /home/rduser/ac.log
printf "%s" "${Mail_error[*]}" | mutt -s "i-Guangdong 场点认证可用性监控" jc.wu@windfindtech.com ronald.zhao@windfindtech.com chaoli.ye@windfindtech.com
}

send_mail
